package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /*
    * 向购物车添加商品
    * */
    void add(ShoppingCart shoppingCart);

    /*
    *根据用户id、菜品id、套餐id查询购物车商品
    * */
    ShoppingCart get(Long userId,Long dishId,Long setmealId);

    /*
    * 将给定购物车id的商品数量加一
    * */
    @Update("update shopping_cart set number = number + #{increment} where id = #{id}")
    void changeNumber(Long id,Integer increment);

    /*
    *根据id删除商品数据
    * */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    /*
    * 查询购物车
    * */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectByUserId(Long userId);
    /*
    * 清空购物车
    * */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);
}


